package com.ws.dz.web.controller;

import com.ws.dz.api.user.UserService;
import com.ws.dz.mapper.user.entity.SysUser;
import com.ws.dz.mapper.user.entity.SysUserInfo;
import com.ws.dz.mapper.user.param.RegisterUser;
import com.ws.dz.mapper.user.param.UpdateUser;
import com.ws.dz.mapper.user.param.UpdateUserInfo;
import com.ws.rain.base.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@Api(tags = "UserController", description = "用户管理")
public class UserController {

    @Reference(loadbalance = "roundrobin",timeout = 1000)
    private UserService userService;

    @PostMapping("/register")
    @ApiOperation("注册用户")
    public R register(RegisterUser user) {
       SysUser sysUser = userService.register(user);
        return R.data(sysUser);
    }

    @PostMapping("/update")
    @ApiOperation("修改用户个人信息")
    public R updateUserInfo(UpdateUserInfo user) {
       SysUserInfo sysUser = userService.updateUserInfo(user);
        return R.data(sysUser);
    }

    @PostMapping("/update/pwd")
    @ApiOperation("修改用户密码")
    public R updatePwd(UpdateUser user) {
        String str = userService.updateUser(user);
        return R.data(str);
    }

    @PostMapping("/update/role")
    @ApiOperation("修改用户角色")
    public R updateRole(UpdateUser user) {
        String str = userService.updateUser(user);
        return R.data(str);
    }


}
